/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Action;

import ActionForm.ApplicantForm;
import Bean.ApplicantBean;
import DAO.ApplicantDAO;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Vietlt
 */
public class ApplicantProcess extends org.apache.struts.action.Action {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ApplicantForm aFrom = (ApplicantForm) form;
        ApplicantBean aB = new ApplicantBean();
        aB.setFirstName(aFrom.getFirstName());
        aB.setLastName(aFrom.getLastName());
        aB.setGender(aFrom.isGender());
        aB.setDob(aFrom.getDob());
        aB.setPhoneNumber(aFrom.getPhoneNumber());
        aB.setEmail(aFrom.getEmail());
        aB.setAddress(aFrom.getAddress());
        aB.setStatus(aFrom.getStatus());
        aB.setSalaryRequirement(aFrom.getSalaryRequirement());
        aB.setLanguage(aFrom.getLanguage());
        aB.setYearOfExperience(aFrom.getYearOfExperience());
        aB.setDegree(aFrom.getDegree());

        Date todayD = new Date(System.currentTimeMillis());
//Khai bao dinh dang ngay thang
        SimpleDateFormat dayFormat = new SimpleDateFormat("dd/MM/yyyy");
//parse ngay thang sang dinh dang va chuyen thanh string.
        String todayS = dayFormat.format(todayD.getTime());

        aB.setCreatedDate(todayS);
        aB.setSkill(aFrom.getSkill());
        aB.setAward(aFrom.getAward());
        String target = "";
        if (new ApplicantDAO().AddNewApplicant(aB) == 1) {
            target = "addOk";
        } else {
            target = "addNo";
        }
        return mapping.findForward(target);
    }
}
